/**
 *desc: 选择评价类型
*/
<template>
  <div class="ratingselect">
    <h1 class="title">商品评价</h1>
    <div class="rating-type">
      <!-- 全部 -->
      <span class="block positive" :class="{'active': selectType===2}" @click="select(2)">
        {{desc.all}}
        <span class="count">{{ratings.length}}</span>
      </span>
      <!-- 好评 -->
      <span class="block positive" :class="{'active': selectType===0}" @click="select(0)">
        {{desc.positive}}
        <span class="count">{{positives.length}}</span>
      </span>
      <!-- 差评 -->
      <span class="block negative" :class="{'active': selectType===1}" @click="select(1)">
        {{desc.negative}}
        <span class="count">{{negatives.length}}</span>
      </span>
    </div>
    <div class="switch" :class="{'on':onlyContent==true}">
      <span class="icon-check_circle" @click="toggleContent"></span>
      <span class="text">只看有内容的评价</span>
    </div>
  </div>
</template>
<script>
const POSITIVE = 0;
const NEGATIVE = 1;
const ALL = 2;
export default {
  name: "",
  props: {
    // 评价
    ratings: {
      type: Array,
      default() {
        return [];
      }
    },
    // 选择查看评价类型,默认查看全部
    selectType: {
      type: Number,
      default: ALL
    },
    // 只看有内容的评价
    onlyContent: {
      type: Boolean,
      default: false
    },
    // 评价标签
    desc: {
      type: Object,
      default() {
        return {
          all: "全部",
          positive: "满意",
          negative: "不满意"
        };
      }
    }
  },
  computed: {
    // 获取好评的数量
    positives() {
      return this.ratings.filter(rating => {
        return rating.rateType === POSITIVE;
      });
    },
    // 获取差评的数量
    negatives() {
      return this.ratings.filter(rating => {
        return rating.rateType === NEGATIVE;
      });
    }
  },
  data() {
    return {};
  },
  methods: {
    select(type) {
      this.$emit("selectTypeChange", type);
    },
    // 切换只看有内容的评价
    toggleContent() {
      this.$emit("toggleContent");
    }
  }
};
</script>
<style lang='stylus' scoped>
.ratingselect {
  .title {
    padding: 10px 18px;
    font-size: 14px;
    line-height: 14px;
  }

  .rating-type {
    padding: 18px 0;
    margin: 0 18px;
    border-bottom: 1px solid #ccc;
    font-size: 0;

    .block {
      display: inline-block;
      height: 16px;
      line-height: 16px;
      padding: 8px 12px;
      margin-right: 8px;
      font-size: 12px;
      border-radius: 1px;

      // 选中的时候字体颜色
      &.active {
        color: #fff;
      }

      // 评价数量
      .count {
        font-size: 8px;
      }

      &.positive {
        background-color: rgba(0, 160, 220, 0.2);

        &.active {
          background-color: rgb(0, 160, 220);
        }
      }

      &.negative {
        background-color: rgba(77, 185, 93, 0.2);

        &.active {
          background-color: rgb(77, 85, 93);
        }
      }
    }
  }

  .switch {
    padding: 12px 18px;
    border-bottom: 1px solid rgba(7, 17, 27, 0.1);

    &.on {
      .icon-check_circle {
        color: #00c850;
      }
    }

    .icon-check_circle {
      margin-right: 4px;
      font-size: 24px;
      line-height: 24px;
      color: rgb(147, 153, 159);
      vertical-align: middle;
    }

    .text {
      font-size: 12px;
      color: rgb(147, 153, 159);
      line-height: 24px;
    }
  }
}
</style>
